package com.jie.other.compose.study03

import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.jie.other.compose.data.TaskItemDTO

@Composable
fun TaskList(
    list : List<TaskItemDTO>,
    closeTaskClick : (TaskItemDTO) -> Unit,
    scrollState : LazyListState = rememberLazyListState(),
    modifier: Modifier = Modifier,
) {
    LazyColumn(
        modifier,
        state = scrollState,
    ) {
        items(
            list,
            key = { task -> task.id }
        ) {
            TaskItem(
                taskName = it.taskName,
                checkedState = it.checkStatus.value,
                onCheckChange = { check ->
                    it.checkStatus.value = check
                },
                closeClick = {
                    closeTaskClick(it)
                })
        }
    }
}